package mskruch.gps;

import java.io.Serializable;

/**
 * GPS Point Data
 * 
 * @author Marcin Skruch
 */
class GpsToolsPoint extends GpsToolsPosition implements Point, Serializable {
    private static final long serialVersionUID = 1L;

    /** Elevation in meters */
	private final Double elevation;

    /** Time in milliseconds */
    private final long time;

    /** Heart rate */
    private final Short heartRate;

    /** Cadence in revolutions per minute */
    private final Short cadence;
    
	GpsToolsPoint(
		double longitude, double latitude, Double elevation, long time,
		Short heartRate, Short cadence)
	{
        super(longitude, latitude);
        this.elevation = elevation;
        this.time = time;
        this.heartRate = heartRate;
        this.cadence = cadence;
    }

    @Override
    public boolean after(Point other) {
        return this.time > other.getTime();
    }

    @Override
    public Short getCadence() {
        return cadence;
    }

    @Override
	public Double getElevation()
	{
        return elevation;
    }

    @Override
    public Short getHeartRate() {
        return heartRate;
    }

    @Override
    public long getTime() {
        return time;
    }

    @Override
    public String toString() {
        return String.format("(%.14f, %.14f, %.1f m.a.s.l; %d cad, %d hr)", getLongitude(), getLatitude(),
                getElevation(), getCadence(), getHeartRate());
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        long temp;
        temp = Double.doubleToLongBits(elevation);
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getLatitude());
        result = prime * result + (int) (temp ^ (temp >>> 32));
        temp = Double.doubleToLongBits(getLongitude());
        result = prime * result + (int) (temp ^ (temp >>> 32));
        result = prime * result + (int) (time ^ (time >>> 32));
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        GpsToolsPoint other = (GpsToolsPoint) obj;
        if (Double.doubleToLongBits(elevation) != Double.doubleToLongBits(other.elevation)) {
            return false;
        }
        if (Double.doubleToLongBits(getLatitude()) != Double.doubleToLongBits(other.getLatitude())) {
            return false;
        }
        if (Double.doubleToLongBits(getLongitude()) != Double.doubleToLongBits(other.getLongitude())) {
            return false;
        }
        if (time != other.time) {
            return false;
        }
        return true;
    }

}
